package com.cmcc.linlaker.ui.query.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.cmcc.linlaker.R;
import com.cmcc.linlaker.ui.query.bean.QueryProjectBean;

import java.util.List;

public class QueryFarmerAdapter extends RecyclerView.Adapter<QueryFarmerAdapter.ViewHolder> {

    private List<QueryProjectBean.QueryProjectData> itemList;
    private Context mContext;

    public QueryFarmerAdapter(Context mContext, List<QueryProjectBean.QueryProjectData> itemList) {
        this.itemList = itemList;
        this.mContext = mContext;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(parent.getContext())
                .inflate(R.layout.query_farmer_item, parent, false));
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        QueryProjectBean.QueryProjectData item = itemList.get(position);

        holder.text_name.setText(item.name);
    }

    public interface OnItemClickListener {
        void onItemClick(int position);
    }

    private OnItemClickListener onItemClickListener;

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
    }

    @Override
    public int getItemCount() {
        return itemList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

        public TextView text_name;


        public ViewHolder(View itemView) {
            super(itemView);
            itemView.setOnClickListener(this);

            text_name = itemView.findViewById(R.id.text_name);
        }

        @Override
        public void onClick(View v) {
            onItemClickListener.onItemClick(getAdapterPosition());
        }
    }

}

